package org.common.utils.generatormapper.entity;
import org.common.utils.database.mapper.AbstractMapper;
import java.util.List;

public class AdventureArchiveMapper extends AbstractMapper<AdventureArchive> {

    private static final String INSERT_TEMPLATE = "insert into `adventure_archive` (`id`, `arcthive_type`, `activate_drop`, `character_piece_level`, `character_piece_drop`, `monster_need_num`, `monster_num_drop`, `boss_need_num`, `boss_num_drop`, `key`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

    private static final String UPDATE_TEMPLATE  = "update `adventure_archive` set `id` = ?, `arcthive_type` = ?, `activate_drop` = ?, `character_piece_level` = ?, `character_piece_drop` = ?, `monster_need_num` = ?, `monster_num_drop` = ?, `boss_need_num` = ?, `boss_num_drop` = ?, `key` = ? where `id` = ?";

    private static final String DELETE_TEMPLATE  = "delete from `adventure_archive` where `id` = ?";

    private static final String SELECT_TEMPLATE = "select `id`, `arcthive_type`, `activate_drop`, `character_piece_level`, `character_piece_drop`, `monster_need_num`, `monster_num_drop`, `boss_need_num`, `boss_num_drop`, `key` from `adventure_archive` where ";

    @Override
    public List<AdventureArchive> select(String whereString , List<Object> params) {
        return executeList(SELECT_TEMPLATE , whereString , params, (resultSet -> {
            AdventureArchive object = new AdventureArchive();
            object.setId(resultSet.getInt(1));
            object.setArcthiveType(resultSet.getInt(2));
            object.setActivateDrop(resultSet.getString(3));
            object.setCharacterPieceLevel(resultSet.getString(4));
            object.setCharacterPieceDrop(resultSet.getString(5));
            object.setMonsterNeedNum(resultSet.getString(6));
            object.setMonsterNumDrop(resultSet.getString(7));
            object.setBossNeedNum(resultSet.getString(8));
            object.setBossNumDrop(resultSet.getString(9));
            object.setKey(resultSet.getInt(10));
            return object;
        }));
    }

    @Override
    public int insert(AdventureArchive object) {
        return insert(List.of(object))[0];
    }

    @Override
    public int[] insert(List<AdventureArchive> list) {
        return executeBatch(INSERT_TEMPLATE , list , (preparedStatement, object) -> {
            preparedStatement.setObject(1 , object.getId());
            preparedStatement.setObject(2 , object.getArcthiveType());
            preparedStatement.setObject(3 , object.getActivateDrop());
            preparedStatement.setObject(4 , object.getCharacterPieceLevel());
            preparedStatement.setObject(5 , object.getCharacterPieceDrop());
            preparedStatement.setObject(6 , object.getMonsterNeedNum());
            preparedStatement.setObject(7 , object.getMonsterNumDrop());
            preparedStatement.setObject(8 , object.getBossNeedNum());
            preparedStatement.setObject(9 , object.getBossNumDrop());
            preparedStatement.setObject(10 , object.getKey());
        });
    }

    @Override
    public int update(AdventureArchive object) {
        return update(List.of(object))[0];
    }

    @Override
    public int[] update(List<AdventureArchive> list) {
        return executeBatch(UPDATE_TEMPLATE , list , (preparedStatement, object) -> {
            preparedStatement.setObject(1 , object.getId());
            preparedStatement.setObject(2 , object.getArcthiveType());
            preparedStatement.setObject(3 , object.getActivateDrop());
            preparedStatement.setObject(4 , object.getCharacterPieceLevel());
            preparedStatement.setObject(5 , object.getCharacterPieceDrop());
            preparedStatement.setObject(6 , object.getMonsterNeedNum());
            preparedStatement.setObject(7 , object.getMonsterNumDrop());
            preparedStatement.setObject(8 , object.getBossNeedNum());
            preparedStatement.setObject(9 , object.getBossNumDrop());
            preparedStatement.setObject(10 , object.getKey());
            preparedStatement.setObject(11 , object.getId());
        });
    }

    @Override
    public int delete(AdventureArchive object) {
        return delete(List.of(object))[0];
    }

    @Override
    public int[] delete(List<AdventureArchive> list) {
        return executeBatch(DELETE_TEMPLATE , list , ((preparedStatement, object) -> {
            preparedStatement.setObject(1 , object.getId());
        }));
    }
}
